import { ComUtils } from "@/utils/Com"
import PageTab from "./PageTab"
import { createSignal, Show } from "solid-js"
export default function (props: any) {
    const [version, setVersion] = createSignal('0.0.1')
    const [isDev, setIsDev] = createSignal(true)

    ComUtils.callChromeMethod<string>('version', {})
        .then((res) => setVersion(res))

    ComUtils.callChromeMethod<boolean>('isDev', {})
        .then((res) => setIsDev(res))
        .catch(() => setIsDev(false))

    const goExtensions = () => {
        ComUtils.callChromeMethod('openTab',{ url: 'chrome://extensions/' })
    }
    return <div class="page w-full h-screen">
        <div class="py-2 px-5 flex items-center justify-between " classList={{ 'bg-[#a72b04]': !isDev() }}>
            <Show when={!isDev()} fallback={<span>&nbsp;</span>}>
                <button onclick={goExtensions}>
                    {ComUtils.tr('need_dev_mode')}
                </button>
            </Show>
            <h3 class=" font-bold flex items-center gap-2">
                <img class="w-6 h-6" src={ComUtils.getResourceUrl('/logo.png')} alt="logo" />
                <span>
                    {ComUtils.tr('app_name')} v{version()}
                </span>
            </h3>
        </div>
        <PageTab />
        <div class="content">
            {props.children}
        </div>
    </div>
}